﻿@model KL.Store.Web.Models.CartCheckOutModel
@using KL.Store.Core;
@using KL.Store.Data;
@using KL.Store.Core.Domain;
@using KL.Store.Core.Domain.Enum;
@using CaptchaMvc.HtmlHelpers;
@{
    var checkOutStyle = 0;
    var processesHidden = false;
    var ctypeclass = "";
    var ctypeprepare = false;
    if (!string.IsNullOrEmpty(Model.CardNumber1))
    {
        var c1firstchar = Model.CardNumber1.Substring(0, 1);
        switch (c1firstchar)
        {
            case "3": ctypeclass = "amex"; ctypeprepare = true; break;
            case "4": ctypeclass = "visa"; ctypeprepare = false; break;
            case "5": ctypeclass = "mastercard"; ctypeprepare = false; break;
            default: ; break;
        }
    }
}
@using (Ajax.BeginForm("RefreshCustom", "Cart", new { }, new AjaxOptions { UpdateTargetId = "checkoutForm", HttpMethod = "Post", LoadingElementId = "LoadingTotal, #LoadingTotalWithCreditCard, #LoadingTotalWithTransfer, #Loading2" }, new { id = "frmRefresh", name = "frmRefresh" }))
{
    @Html.HiddenFor(m => m.SelectedAction, new { @autocomplete = "off" })
    @Html.HiddenFor(m => m.PaymentType, new { @autocomplete = "off" })
    @Html.HiddenFor(m => m.SelectedPos, new { @autocomplete = "off" })
    @Html.HiddenFor(m => m.SelectedInstallment, new { @autocomplete = "off" })
    @Html.HiddenFor(m => m.SelectedCargoCompanyId, new { @autocomplete = "off" })
    @Html.HiddenFor(m => m.SelectedBank, new { @autocomplete = "off" })
    @Html.HiddenFor(m => m.Type3D, new { @autocomplete = "off" })
    @Html.HiddenFor(m => m.AgreementChecked, new { @autocomplete = "off" })
    <input type="hidden" name="IsTotalPayment" value="1" />   
    <div class="checkOut-inner">
        @*Adres Bilgileri*@
        <div class="checkOut-section">
            <div class="col-sm-4 first last">
                <h3>Ödeme Miktarı</h3>
                <div class="col-xs-9 first">
                    <label for="TotalPayment">Ödeme Miktarı (TL)</label>
                    @Html.TextBoxFor(m => m.TotalPayment, new { @class = "form-control txtPaymentAmount" })
                </div>
                <div class="col-xs-3 first">
                    <br />
                    <button type="button" class="btn btn-custom2" onclick="frmSubmitRefresh();">Hesapla</button>
                </div>
            </div>
        </div>
        <div class="checkOut-section chkpayopts chkpayopts2">
            <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12 first checkOut-select-pos">
                @*pivot 110*@
                <div id="pivot-110" class="pivot" style="display: @(Model.PaymentType == PaymentTypes.KrediKart ? "block" : "none")">
                    <h3>Lütfen ödeme yapmak istediğiniz kartı seçiniz:</h3>
                    @{
    var posListe = dbPos.GetList().Where(o => o.PosVoucher == "M");
    foreach (Pos pos in posListe)
    {
        pos.PosInstallment = dbPos.GetInstallmentList(pos.PosId, Model.TotalPayment, Model.TotalPayment, 0, 0);
    }

    var maxInstallment = posListe.Max(z => z.PosInstallment.Count());
    if (maxInstallment > Model.MaxInstallmentCount && Model.MaxInstallmentCount > 0)
    {
        maxInstallment = Model.MaxInstallmentCount;
    }
    var installmentClass = "col-xs-2 col-md-1";
    var maxInstallmentCustom = 0;
    switch (maxInstallment)
    {
        case 1:
            installmentClass = "col-xs-9 col-md-9";
            maxInstallmentCustom = 1;
            break;
        case 2:
        case 3:
            installmentClass = "col-xs-3 col-md-3";
            maxInstallmentCustom = 3;
            break;
        default:
            installmentClass = "col-xs-2 col-md-1";
            maxInstallmentCustom = 9;
            break;
    }
                    }
                    <div class="tInstallment tSelectable">
                        <div class="tRow tRowHead">
                            <div class="tCol tColWide col-xs-2"><span>Kart Seçenekleri</span></div>
                            <div class="tCol tColAddtInst col-xs-2 col-md-1">
                                <span>Artı Taksit</span>
                            </div>
                            @for (var j = 1; j <= maxInstallmentCustom; j++)
                            {
                                if (j == 1)
                                {
                                <div class="tCol @installmentClass"><span>Tek Çekim</span></div>
                                }
                                else if (j == 4)
                                {
                                <div class="tCol @installmentClass"><span>@j Taksit</span></div>
                                <div class="tCol tColMSpace col-xs-2 hidden-md hidden-lg">&nbsp;</div>
                                }
                                else
                                {
                                <div class="tCol @installmentClass"><span>@j Taksit</span></div>
                                }

                            }
                            <div class="clearfix"></div>
                        </div>


                        @foreach (var item in posListe)
                        {
                            if (item.PosInstallment.Count() > 0)
                            {
                                var instCounter = 1;
                            <div class="tRow tRowBody @{if (item.PosId == Model.SelectedPos)
                                                        {<text>tRowSelected</text>}} PosGroup@(item.PosGroup)">
                                <div class="tCol tColWide tColImage col-xs-2">
                                    <img alt="" id="Pos_@(item.PosId)" src="@(Parameters.WebSiteImageUrl)/pos/@(item.PosId).jpg" />
                                </div>
                                <div class="tCol tColAddtInst col-xs-2 col-md-1"><span>@{ @(item.PosInstallment.Count() > 1 && item.PosInstallment.Where(p => p.InstallmentNumber > 1).FirstOrDefault().AdditionInstallment > 0 ? "+" + item.PosInstallment.Where(p => p.InstallmentNumber > 1).FirstOrDefault().AdditionInstallment.ToString() + " Taksit" : "-") }</span></div>
                                @*@if (!string.IsNullOrEmpty(item.Description))
                                                {
                                                    <tr class="installment-warning">
                                                        <td style="text-align: center" class="installment" colspan="4">@Html.Raw(item.Description)</td>
                                                    </tr>
                                                }*@

                                @if (item.PosInstallment.FirstOrDefault().InstallmentNumber > 1)
                                {
                                    for (var i = 1; i < item.PosInstallment.FirstOrDefault().InstallmentNumber; i++)
                                    {
                                    <div class="tCol tColNormal @installmentClass"><span>-</span></div>
                                        instCounter++;
                                    }
                                }
                                @foreach (var pi in item.PosInstallment)
                                {
                                    if (Model.MaxInstallmentCount < pi.InstallmentNumber && Model.MaxInstallmentCount > 0)
                                    {
                                        continue;
                                    }
                                    var whl = true;
                                    while (whl == true)
                                    {
                                        if (pi.InstallmentNumber == instCounter)
                                        {
                                            whl = false;
                                            continue;
                                        }
                                    @Html.Raw("<div class=\"tCol tColNormal " + installmentClass + "\"><span>-</span></div>");

                                                                                                                             instCounter++;
                                    }
                                    var ustSatir = pi.InstallmentNumber + pi.AdditionInstallment > 1 ? pi.InstallmentNumber + pi.AdditionInstallment + " x " + (((pi.InstallmentNumber == 1 ? Model.TotalPaymentWithCreditCard : Model.TotalPayment) * pi.CommissionRate) / pi.TotalInstallment).ToString("###,###,##0.00") : "Tek Çekim";
                                    <div class="tCol tColNormal @{if (pi.InstallmentNumber == Model.SelectedInstallment && item.PosId == Model.SelectedPos)
                                                                  {<text>tColSelected</text>}} @installmentClass@{ if (pi.Bold)
                                                                                                                   {<text> tColBold</text>;
                                                                                                                   }}" onclick="PosAndInstallmentSelect(@item.PosId, @pi.InstallmentNumber)">
                                        <span>@ustSatir<br />
                                            @(pi.TotalInterestPrice.ToString("###,###,##0.00"))</span>
                                    </div>
                                                                                                                   if (instCounter == 4)
                                                                                                                   {
                                    <div class="tCol tColMSpace col-xs-2 hidden-md hidden-lg">&nbsp;</div>
                                                                                                                   }
                                                                                                                   instCounter++;
                                }
                                @if (instCounter < maxInstallmentCustom + 1)
                                {
                                    for (var i = instCounter; i <= maxInstallmentCustom; i++)
                                    {
                                    @Html.Raw("<div class=\"tCol tColNormal " + installmentClass + "\"><span>-</span></div>");
                                                                                                                             if (instCounter + i == 6)
                                                                                                                             {
                                    <div class="tCol tColMSpace col-xs-2 hidden-md hidden-lg">&nbsp;</div>
                                                                                                                             }
                                    }
                                }
                                <div class="clearfix"></div>
                            </div>    
                            }
                        }
                    </div>
                    @if (posListe.Count(o => o.Description != null && o.Description != "") > 0)
                    {
                        <hr />
                        <div class="installmentDescriptions">
                            <table class="table table-bordered">
                                @foreach (var pos in posListe)
                                {
                                    if (!string.IsNullOrEmpty(pos.Description))
                                    {
                                    <tr>
                                        <td>@pos.CardName</td>
                                        <td>@pos.Description</td>
                                    </tr>
                                    }
                                }
                            </table>
                        </div>
                    }
                    <hr />
                    <div class="clearfix"></div>

                    <div class="col-md-4 first last">
                        <h3>Borçlu Bilgileri</h3>
                        <div class="col-sm-10 first">
                            <label for="FirstName">Borçlunun Adı</label>
                            <span class="required">*</span>
                            @Html.TextBoxFor(m => m.FirstName, new { @class = "form-control" })
                            <br />
                        </div>
                        <div class="clearfix"></div>
                        <div class="col-sm-10 first">
                            <label for="LastName">Borçlunun Soyadı</label>
                            <span class="required">*</span>
                            @Html.TextBoxFor(m => m.LastName, new { @class = "form-control" })
                            <br />
                        </div>
                        <div class="clearfix"></div>
                        <div class="clearfix"></div>
                        <div class="col-sm-10 first">
                            <label for="TCKimlik">Borçlunun TC Kimlik Numarası</label>
                            <span class="required">*</span>
                            @Html.TextBoxFor(m => m.TCKimlik, new { @class = "form-control TcKimlikNo", @maxlength = "11" })
                            <br />
                        </div>
                        <div class="clearfix"></div>
                        <div class="col-sm-10 first">
                            <label for="LastName">Borçlunun Telefon Numarası</label>
                            <span class="required">*</span>
                            @Html.TextBoxFor(m => m.Mobile, new { @class = "form-control TelefonNo" })
                            <br />
                        </div>
                    </div>
                    <div class="col-md-8 last borderleft">
                        <h3>Lütfen kart bilgilerinizi giriniz</h3>
                        <div class="col-xs-12 col-sm-12 col-md-6 first last checkout-card-info">
                            <table style="display: @(Model.PosInstallmentList.Count > 0 ? "block" : "none"); width:100%;">
                                <tbody>
                                    <tr>
                                        <td style="border: none">
                                            <label for="CardOwnerName">@Html.LabelFor(m => m.CardOwnerName)</label>
                                        </td>
                                        <td style="border: none">:</td>
                                        <td style="border: none">
                                            @Html.TextBoxFor(m => m.CardOwnerName, new { @style = "width:96%;", @class = "kkisim kart_onyuzde", @autocomplete = "off" })
                                        </td>
                                    </tr>
                                    <tr>
                                        <td style="border: none; width: 19%;">
                                            @Html.LabelFor(m => m.CardNumber)
                                        </td>
                                        <td style="border: none; width: 1%;">:</td>
                                        <td style="border: none; width: 80%;">
                                            @Html.TextBoxFor(m => m.CardNumber1, new { @style = "width:45px", @maxlength = "4", @class = "number kkn kkn1 kart_onyuzde", @onkeydown = "return KeyDown(event)", @onkeyup = "KeyUp(this)", @autocomplete = "off", @id = "number1" })
                                            <span>-</span>
                                            @Html.TextBoxFor(m => m.CardNumber2, new { @style = "width:45px", @maxlength = "4", @class = "number kkn kkn2 kart_onyuzde", @onkeydown = "return KeyDown(event)", @onkeyup = "KeyUp(this)", @autocomplete = "off", @id = "number2" })
                                            <span>-</span>
                                            @Html.TextBoxFor(m => m.CardNumber3, new { @style = "width:45px", @maxlength = "4", @class = "number kkn kkn3 kart_onyuzde", @onkeydown = "return KeyDown(event)", @onkeyup = "KeyUp(this)", @autocomplete = "off", @id = "number3" })
                                            <span id="number3sep">-</span>
                                            @Html.TextBoxFor(m => m.CardNumber4, new { @style = "width:45px", @maxlength = "4", @class = "number kkn kkn4 kart_onyuzde", @onkeydown = "return KeyDown(event)", @onkeyup = "KeyUp(this)", @autocomplete = "off", @id = "number4" })
                                        </td>
                                    </tr>
                                    <tr>
                                        <td style="border: none">
                                            @Html.LabelFor(m => m.ValidMonth)
                                        </td>
                                        <td style="border: none">:</td>
                                        <td style="border: none">
                                            @{
                    var months = new List<SelectListItem> {
                                                                            new SelectListItem {Text = "Ay", Value = "0"},
                                                                            new SelectListItem {Text = "01", Value = "1"},
                                                                            new SelectListItem {Text = "02", Value = "2"},
                                                                            new SelectListItem {Text = "03", Value = "3"},
                                                                            new SelectListItem {Text = "04", Value = "4"},
                                                                            new SelectListItem {Text = "05", Value = "5"},
                                                                            new SelectListItem {Text = "06", Value = "6"},
                                                                            new SelectListItem {Text = "07", Value = "7"},
                                                                            new SelectListItem {Text = "08", Value = "8"},
                                                                            new SelectListItem {Text = "09", Value = "9"},
                                                                            new SelectListItem {Text = "10", Value = "10"},
                                                                            new SelectListItem {Text = "11", Value = "11"},
                                                                            new SelectListItem {Text = "12", Value = "12"},
                                                                          };
                    var years = new List<SelectListItem>();
                    years.Add(new SelectListItem { Text = "Yıl", Value = "0" });
                    var yil = Parameters.Now.Year;
                    for (var i = yil; i <= yil + 12; i++)
                    {
                        years.Add(new SelectListItem { Text = i.ToString(), Value = i.ToString() });
                    }
                                            }
                                            @Html.DropDownListFor(m => m.ValidMonth, months, new { @style = "width:55px", @class = "kkay kart_onyuzde" })
                                            / @Html.DropDownListFor(m => m.ValidYear, years, new { @style = "width:75px", @class = "kkyil kart_onyuzde" })
                                        </td>
                                    </tr>
                                    <tr>
                                        <td style="border: none">
                                            @Html.LabelFor(m => m.CVV)
                                        </td>
                                        <td style="border: none">:</td>
                                        <td style="border: none">
                                            @Html.TextBoxFor(m => m.CVV, new { @style = "width:40px;float:left;", @maxlength = "3", @class = "number kkcvv kart_arkayuzde", @onkeydown = "return KeyDown(event)", @onkeyup = "KeyUp(this)", @autocomplete = "off" })
                                            <div style="margin-left: 7px; float: left;@{if (Model.Type3D == "Yok")
                                                                                        {<text> display: none;</text>}}">
                                                @Html.HiddenFor(m => m.Type3D)
                                                @if (Model.Type3D == "Var" || Model.Type3D == "")
                                                { 
                                                    @Html.CheckBoxFor(m => m.Use3D)
                                                }
                                                else if (Model.Type3D == "Zorunlu")
                                                {
                                                    <input type="hidden" value="true" name="Use3D" />
                                                    <input type="checkbox" name="Use3DPlaceHolder" disabled="disabled" title="Bu kart ile yapılan alışverişlerde 3D ödeme zorunludur." />
@*Html.CheckBoxFor(m => m.Use3D, new { @disabled = "disabled", @checked = "checked", @title = "Bu kart ile yapılan alışverişlerde 3D ödeme zorunludur." })*@
                                                    <script>
                                                        $(document).ajaxComplete(function ()
                                                        {
                                                            $("input[name=Use3DPlaceHolder]").prop("checked", true);
                                                        });
                                                    </script>
                                                }
                                                else
                                                {
                                                    <input type="hidden" value="false" name="Use3D" />
                                                }
                                                <label for="Use3D" @{if (Model.Type3D == "Zorunlu")
                                                                     { <text> title="Bu kart ile yapılan alışverişlerde 3D ödeme zorunludur."</text>}}>
                                                    <img src="/Images/@Parameters.Theme/checkout-card-3d-ssl.png" style="height:35px;" />
                                                    3D Ödeme</label>
                                            </div>
                                        </td>
                                    </tr>
                                </tbody>
                            </table>
                            @*Html.DisplayTextFor(model => model.Message4)*@
                        </div>
                        <div class="col-sm-5 last kart_onizleme">
                            <div id="kart_onyuz" class="kart_kalip">
                                <div id="kart_cvvamex" class="kart_alan">@(Model.CardNumber1)</div>
                                <div id="kart_num1" class="kart_alan kart_alan_num">@(Model.CardNumber1)</div>
                                <div id="kart_num2" class="kart_alan kart_alan_num">@(Model.CardNumber2)</div>
                                <div id="kart_num3" class="kart_alan kart_alan_num">@(Model.CardNumber3)</div>
                                <div id="kart_num4" class="kart_alan kart_alan_num">@(Model.CardNumber4)</div>
                                <div id="kart_isim" class="kart_alan">@(Model.CardOwnerName)</div>
                                <div id="kart_tarih" class="kart_alan">@(Model.ValidMonth > 0 ? (Model.ValidMonth < 10 ? "0" + Model.ValidMonth.ToString() : Model.ValidMonth.ToString()) : "")@{if (Model.ValidMonth > 0 && Model.ValidYear > 0)
                                                                                                                                                                                                 {
                                    <text>/</text>
                                                                                                                                                                                                 }}@(Model.ValidYear > 0 ? Model.ValidYear.ToString().Substring(2, 2) : "")
                                </div>
                                <div id="kart_tip" class="@(ctypeclass)">
                                </div>
                            </div>
                            <div id="kart_arkayuz" class="kart_kalip">
                                <div id="kart_cizgi"></div>
                                <div id="kart_cvv_bg"></div>
                                <div id="kart_cvv">@(Model.CVV)</div>
                            </div>
                        </div>
                    </div>
                    @if (!Model.CustomPaymentCaptchaVerified)
                    {
                        <input type="hidden" name="captchaAvailable" value="1" />
                    }
                    else
                    {
                        <input type="hidden" name="captchaAvailable" value="0" />
                    }
                </div>
                <div class="clearfix"></div>
            </div>

            <div class="clearfix"></div>
        </div>
        <div class="checkOut-section" id="checkOut-final">
            <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12 first last">
                <table style="width: 100%;">
                    <tbody>
                        @if (!string.IsNullOrEmpty(Model.Message1) || !string.IsNullOrEmpty(Model.Message2) || !string.IsNullOrEmpty(Model.Message3) || !string.IsNullOrEmpty(Model.Message4) || !string.IsNullOrEmpty(Model.Message5) || !string.IsNullOrEmpty(Model.Message6) || !string.IsNullOrEmpty(Model.Message7) || !string.IsNullOrEmpty(Model.Message8) || !string.IsNullOrEmpty(Model.Message9) || !string.IsNullOrEmpty(Model.Message10) || !string.IsNullOrEmpty(Model.Message11))
                        {
                            <tr>
                                <td style="border: none; width: 100%; padding-bottom: 20px;" colspan="2">
                                    <div class="bg-danger checkoutErrors">
                                        <p>İşleminiz gerçekleştirilirken aşağıdaki hata(lar) ile karşılaşıldı:</p>
                                        <ul>
                                            @(Html.Raw(string.IsNullOrEmpty(Model.Message2) ? "" : "<li>" + Html.DisplayTextFor(model => model.Message2) + "</li>"))
                                            @(Html.Raw(string.IsNullOrEmpty(Model.Message3) ? "" : "<li>" + Html.DisplayTextFor(model => model.Message3) + "</li>"))
                                            @(Html.Raw(string.IsNullOrEmpty(Model.Message4) ? "" : "<li>" + Html.DisplayTextFor(model => model.Message4) + "</li>"))
                                            @(Html.Raw(string.IsNullOrEmpty(Model.Message5) ? "" : "<li>" + Html.DisplayTextFor(model => model.Message5) + "</li>"))
                                            @(Html.Raw(string.IsNullOrEmpty(Model.Message6) ? "" : "<li>" + Html.DisplayTextFor(model => model.Message6) + "</li>"))
                                            @(Html.Raw(string.IsNullOrEmpty(Model.Message7) ? "" : "<li>" + Html.DisplayTextFor(model => model.Message7) + "</li>"))
                                            @(Html.Raw(string.IsNullOrEmpty(Model.Message8) ? "" : "<li>" + Html.DisplayTextFor(model => model.Message8) + "</li>"))
                                            @(Html.Raw(string.IsNullOrEmpty(Model.Message9) ? "" : "<li>" + Html.DisplayTextFor(model => model.Message9) + "</li>"))
                                            @(Html.Raw(string.IsNullOrEmpty(Model.Message10) ? "" : "<li>" + Html.DisplayTextFor(model => model.Message10) + "</li>"))
                                            @(Html.Raw(string.IsNullOrEmpty(Model.Message11) ? "" : "<li>" + Html.DisplayTextFor(model => model.Message11) + "</li>"))

                                        </ul>
                                    </div>
                                </td>
                            </tr>
                            <script>
                                var topPos = $('.checkoutErrors').offset();
                                if ($.browser.webkit)
                                {
                                    $('body:not(:animated)').animate({ scrollTop: topPos.top - 75 }, 'slow');
                                }
                                else
                                {
                                    $('html:not(:animated)').animate({ scrollTop: topPos.top - 75 }, 'slow');
                                }
                            </script>
                        }
                        <tr>
                            <td style="border: none; width: 100%; padding-right: 20px;" class="alignright">
                                <span class="checkout-confirm">
                                    <input id="ChkConfirm" type="checkbox" @{if (Model.AgreementChecked == 1)
                                                                             {<text>checked="checked"</text>}} />
                                    <label for="ChkConfirm"><a class="agreement" onclick="contractview();" href="#dialog-contract">Ödeme Onay Koşulları</a>nı onaylıyorum </label>
                                </span>
                                <div style="position: relative; float: left;">
                                    <div id="Loading2" class="LoadingSmall left">
                                        <img src="/Images/@(Parameters.Theme)/loadingSmall.gif" alt="Loading" />
                                    </div>
                                </div>
                            </td>
                            <td style="border: none" class="alignright">
                                <a class="btn btn-custom1 paymentButton" onclick="frmpost()">
                                    <span>Ödeme Yap</span>
                                </a>
                            </td>
                        </tr>
                    </tbody>
                </table>
            </div>

            <div class="clearfix"></div>
        </div>
    </div>
    <div style="display: none;">
        <div id="address-update" title="Adres"></div>
        <div id="dialog-form" title="Adres"></div>
        <div style="margin: 10px 0;" id="cart-installment-table">
            @{
                                                                             var posListe2 = dbPos.GetList().Where(o => o.PosVoucher == "M");
                                                                             foreach (Pos pos in posListe2)
                                                                             {
                                                                                 pos.PosInstallment = dbPos.GetInstallmentList(pos.PosId, 1, (Model.TotalPaymentWithCreditCard + Model.CargoPrice), 0, 0);
                                                                             }

                                                                             var maxInstallment2 = posListe2.Max(z => z.PosInstallment.Count());
                                                                             if (maxInstallment2 > Model.MaxInstallmentCount && Model.MaxInstallmentCount > 0)
                                                                             {
                                                                                 maxInstallment2 = Model.MaxInstallmentCount;
                                                                             }
                                                                             var installmentClass2 = "col-xs-2 col-md-1";
                                                                             var maxInstallmentCustom2 = 0;
                                                                             switch (maxInstallment2)
                                                                             {
                                                                                 case 1:
                                                                                     installmentClass2 = "col-xs-9 col-md-9";
                                                                                     maxInstallmentCustom2 = 1;
                                                                                     break;
                                                                                 case 2:
                                                                                 case 3:
                                                                                     installmentClass2 = "col-xs-3 col-md-3";
                                                                                     maxInstallmentCustom2 = 3;
                                                                                     break;
                                                                                 default:
                                                                                     installmentClass2 = "col-xs-2 col-md-1";
                                                                                     maxInstallmentCustom2 = 9;
                                                                                     break;
                                                                             }
            }
            <div class="tNotSelectable">
                <div class="tRow tRowHead">
                    <div class="tCol tColWide col-xs-2"><span>Kart Seçenekleri</span></div>
                    <div class="tCol tColAddtInst col-xs-2 col-md-1">
                        <span>Artı Taksit</span>
                    </div>
                    @for (var j = 1; j <= maxInstallmentCustom2; j++)
                    {
                        if (j == 1)
                        {
                        <div class="tCol @installmentClass2"><span>Tek Çekim</span></div>
                        }
                        else if (j == 4)
                        {
                        <div class="tCol @installmentClass2"><span>@j Taksit</span></div>
                        <div class="tCol tColMSpace col-xs-2 hidden-md hidden-lg">&nbsp;</div>
                        }
                        else
                        {
                        <div class="tCol @installmentClass2"><span>@j Taksit</span></div>
                        }

                    }
                    <div class="clearfix"></div>
                </div>


                @foreach (var item in posListe2)
                {
                    if (item.PosInstallment.Count() > 0)
                    {
                        var instCounter = 1;
                    <div class="tRow tRowBody  PosGroup@(item.PosGroup)">
                        <div class="tCol tColWide tColImage col-xs-2">
                            <img alt="" id="Pos_@(item.PosId)" src="@(Parameters.WebSiteImageUrl)/pos/@(item.PosId).jpg" />
                        </div>
                        <div class="tCol tColAddtInst col-xs-2 col-md-1"><span>@{ @(item.PosInstallment.Count() > 1 && item.PosInstallment.Where(p => p.InstallmentNumber > 1).FirstOrDefault().AdditionInstallment > 0 ? "+" + item.PosInstallment.Where(p => p.InstallmentNumber > 1).FirstOrDefault().AdditionInstallment.ToString() + " Taksit" : "-") }</span></div>
                        @*@if (!string.IsNullOrEmpty(item.Description))
                                                {
                                                    <tr class="installment-warning">
                                                        <td style="text-align: center" class="installment" colspan="4">@Html.Raw(item.Description)</td>
                                                    </tr>
                                                }*@
                        @if (item.PosInstallment.FirstOrDefault().InstallmentNumber > 1)
                        {
                            for (var i = 1; i < item.PosInstallment.FirstOrDefault().InstallmentNumber; i++)
                            {
                            <div class="tCol tColNormal @installmentClass2"><span>-</span></div>
                                instCounter++;
                            }
                        }

                        @foreach (var pi in item.PosInstallment)
                        {
                            if (Model.MaxInstallmentCount < pi.InstallmentNumber && Model.MaxInstallmentCount > 0)
                            {
                                continue;
                            }
                            var whl = true;
                            while (whl == true)
                            {
                                if (pi.InstallmentNumber == instCounter)
                                {
                                    whl = false;
                                    continue;
                                }
                            <div class="tCol tColNormal @installmentClass2"><span>-</span></div>
                                instCounter++;
                            }
                            var ustSatir = pi.InstallmentNumber + pi.AdditionInstallment > 1 ? pi.InstallmentNumber + pi.AdditionInstallment + " x " + (((pi.InstallmentNumber == 1 ? Model.TotalPaymentWithCreditCard : Model.TotalPayment) * pi.CommissionRate) / pi.TotalInstallment).ToString("###,###,##0.00") : "Tek Çekim";
                            <div class="tCol tColNormal @installmentClass2@{ if (pi.Bold)
                                                                             {<text> tColBold</text>;
                                                                             }}">
                                <span>@ustSatir<br />
                                    @(pi.TotalInterestPrice.ToString("###,###,##0.00"))</span>
                            </div>
                                                                             if (instCounter == 4)
                                                                             {
                            <div class="tCol tColMSpace col-xs-2 hidden-md hidden-lg">&nbsp;</div>
                                                                             }
                                                                             instCounter++;
                        }
                        @if (instCounter < maxInstallmentCustom2 + 1)
                        {
                            for (var i = instCounter; i <= maxInstallmentCustom2; i++)
                            {
                            <div class="tCol tColNormal zz @installmentClass2"><span>-</span></div>
                                if (instCounter + i == 6)
                                {
                            <div class="tCol tColMSpace col-xs-2 hidden-md hidden-lg">&nbsp;</div>
                                }
                            }
                        }
                        <div class="clearfix"></div>
                    </div>
                    }
                }
            </div>

            @if (posListe2.Count(o => o.Description != null && o.Description != "") > 0)
            {
                <hr />
                <div class="installmentDescriptions">
                    <table class="table table-bordered">
                        @foreach (var pos in posListe2)
                        {
                            if (!string.IsNullOrEmpty(pos.Description))
                            {
                            <tr>
                                <td>@pos.CardName</td>
                                <td>@pos.Description</td>
                            </tr>
                            }
                        }
                    </table>
                </div>
            }
            <div class="clearfix"></div>
        </div>
    </div>
    <script type="text/javascript">
        $('.LoadingSmall').hide();

        $('.txtPaymentAmount').focus(function ()
        {
            if ($(this).val() == 0)
            {
                $(this).val('');
            }
        });

        /*Kredi Kartı Önizleme*/
        if ($(window).width() > 767)
        {

            $('.kart_onyuzde').focus(function ()
            {
                kartonyuzgoster();
                $('.kart_alan').removeClass('focused');
                if ($(this).hasClass('kkn1'))
                {
                    $('#kart_num1').addClass('focused');
                }
                else if ($(this).hasClass('kkn2'))
                {
                    $('#kart_num2').addClass('focused');
                }
                else if ($(this).hasClass('kkn3'))
                {
                    $('#kart_num3').addClass('focused');
                }
                else if ($(this).hasClass('kkn4'))
                {
                    $('#kart_num4').addClass('focused');
                }
                else if ($(this).hasClass('kkisim'))
                {
                    $('#kart_isim').addClass('focused');
                }
                else if ($(this).hasClass('kkay') || $(this).hasClass('kkyil'))
                {
                    $('#kart_tarih').addClass('focused');
                }
                else if ($(this).hasClass('kkcvv'))
                {
                    $('#kart_cvvamex').addClass('focused');
                }
            });
            $('.kart_arkayuzde').live('focus', function ()
            {
                kartarkayuzgoster();
            });
            $('.kart_arkayuzde').live('focusout', function ()
            {
                kartonyuzgoster();
            });
            $('.kkn1').keyup(function ()
            {
                $('#CVV').removeClass('kart_arkayuzde');
                $('#CVV').removeClass('kart_onyuzde');
                $('#kart_num1').html($(this).val());
                var firstChar = $(this).val().substring(0, 1);
                var secondChar = $(this).val().substring(1, 1);
                if (firstChar == '4')
                {
                    $('#kart_tip').attr('class', 'visa');
                    $('#CVV').removeClass('kart_onyuzde');
                    $('#CVV').addClass('kart_arkayuzde');
                    amexiptal();
                }
                else if (firstChar == '5')
                {
                    $('#kart_tip').attr('class', 'mastercard');
                    $('#CVV').removeClass('kart_onyuzde');
                    $('#CVV').addClass('kart_arkayuzde');
                    amexiptal();
                }
                else if (firstChar == '3')
                {
                    $('#kart_tip').attr('class', 'amex');
                    $('#CVV').removeClass('kart_arkayuzde');
                    $('#CVV').addClass('kart_onyuzde');
                    amexhazirla();
                }
                else
                {
                    $('#kart_tip').attr('class', '');
                }
                $('#kart_num1').addClass('focused')
            });
            $('.kart_onyuzde').keyup(function ()
            {
                $('.kart_alan').removeClass('focused');
                if ($(this).hasClass('kkn2'))
                {
                    $('#kart_num2').html($(this).val()).addClass('focused');
                }
                else if ($(this).hasClass('kkn3'))
                {
                    $('#kart_num3').html($(this).val()).addClass('focused');
                }
                else if ($(this).hasClass('kkn4'))
                {
                    $('#kart_num4').html($(this).val()).addClass('focused');
                }
                else if ($(this).hasClass('kkisim'))
                {
                    $('#kart_isim').html($(this).val()).addClass('focused');
                }
            });
            $('.kkay').change(function ()
            {
                tarihgoster();
            });
            $('.kkyil').change(function ()
            {
                tarihgoster();
            });
            $('.kkcvv ').keyup(function ()
            {
                $('.kart_alan').removeClass('focused');
                if ($(this).hasClass('kkcvv'))
                {
                    $('#kart_cvv').html($(this).val()).addClass('focused');
                    $('#kart_cvvamex').html($(this).val()).addClass('focused');
                }
            });

            function amexhazirla()
            {
                $('input#number1').attr('maxlength', '4');
                $('input#number2').attr('maxlength', '6');
                $('input#number3').attr('maxlength', '5');
                //$('input#number4').attr('maxlength', '0');
                $('input#number4').hide();
                $('#checkoutForm .chkpayopts .checkout-card-info input.number.kkn').css('width', '26%');
                $('#number3sep').css('visibility', 'hidden');

                $('#cvvlabel').html('Güvenlik Kodu (CID)');
                $('input#CVV').attr('maxlength', '4');

                $('#kart_cvvamex').show();
                $('#kart_cvv').hide();

                $('.kart_onizleme #kart_onyuz.kart_kalip #kart_num1').css({ 'left': '15px', 'width': '45px' });
                $('.kart_onizleme #kart_onyuz.kart_kalip #kart_num2').css({ 'left': '75px', 'width': '65px' });
                $('.kart_onizleme #kart_onyuz.kart_kalip #kart_num3').css({ 'left': '155px', 'width': '55px' });
                $('.kart_onizleme #kart_onyuz.kart_kalip #kart_num4').css({ 'display': 'none', 'left': '160px', 'width': '45px' });
            }
            function amexiptal()
            {
                $('input#number1').attr('maxlength', '4');
                $('input#number2').attr('maxlength', '4');
                $('input#number3').attr('maxlength', '4');
                //$('input#number4').attr('maxlength', '4');
                $('input#number4').show();
                $('#checkoutForm .chkpayopts .checkout-card-info input.number.kkn').css('width', '45px');
                $('#number3sep').css('visibility', 'visible');

                $('#cvvlabel').html('Güvenlik Kodu (CVV)');
                $('input#CVV').attr('maxlength', '3');

                $('#kart_cvv').show();
                $('#kart_cvvamex').hide();

                $('.kart_onizleme #kart_onyuz.kart_kalip #kart_num1').css({ 'left': '10px', 'width': '45px' });
                $('.kart_onizleme #kart_onyuz.kart_kalip #kart_num2').css({ 'left': '60px', 'width': '45px' });
                $('.kart_onizleme #kart_onyuz.kart_kalip #kart_num3').css({ 'left': '110px', 'width': '45px' });
                $('.kart_onizleme #kart_onyuz.kart_kalip #kart_num4').css({ 'display': 'block', 'left': '160px', 'width': '45px' });


            }

            function tarihgoster()
            {
                var tarihay = $('.kkay').val();
                if (tarihay < 10)
                {
                    tarihay = "0" + tarihay;
                }
                var tarihyil = $('.kkyil').val().substr(2, 2);
                $('#kart_tarih').html(tarihay + ' / ' + tarihyil);
            }
            function kartonyuzgoster()
            {
                $('#kart_arkayuz').animate({ 'width': '0px' }, 750, function ()
                {
                    $('#kart_arkayuz').hide();
                    $('#kart_onyuz').animate({ 'width': '100%' }).show();
                });
            }
            function kartarkayuzgoster()
            {
                $('#kart_onyuz').animate({ 'width': '0px' }, 750, function ()
                {
                    $('#kart_onyuz').hide();
                    $('#kart_arkayuz').animate({ 'width': '100%' }).show();
                });
            }
        }
        $(document).ready(function ()
        {
            @if (ctypeprepare)
            {
                <text>amexhazirla();</text>
            }
        });


        /*Kredi Kartı Önizleme*/

        $('#ChkConfirm').change(function ()
        {
            if ($(this).is(":checked"))
            {
                $('#AgreementChecked').val('1');
            }
            else
            {
                $('#AgreementChecked').val('0');
            }
        });

        $('a.payment-switch').click(function ()
        {
            var qsId = $(this).attr('href').split("_")[1];

            $('.pivot').hide();
            $('#pivot-' + qsId).show();
            $('#PaymentType').val(qsId);

            $(".payment-switch").removeClass("active");
            $(this).addClass("active");

            return false;
        });
        function PosSelect(id)
        {
            $('#SelectedPos').val(id);
            $('.paymentButton').css("visibility", "hidden");
            $('#frmRefresh').submit();
        }
        function PosAndInstallmentSelect(posId, instId)
        {
            $('#SelectedPos').val(posId);
            $('#SelectedInstallment').val(instId);
            $('.paymentButton').css("visibility", "hidden");
            $('#frmRefresh').submit();
        }
        $('.tSelectable .tRow .tCol.tColNormal').click(function ()
        {
            if ($(this).html() != '<span>-</span>')
            {
                $('.tSelectable .tRow .tCol.tColNormal').removeClass('tColSelected');
                $('.tSelectable .tRow').removeClass('tRowSelected');
                $(this).addClass('tColSelected');
                $(this).parent().addClass('tRowSelected');
            }
            else
            {
                alert('Geçersiz taksit seçimi.');
            }
        });
        function frmpost()
        {
            $('#SelectedAction').val("110");
            if ($("#ChkConfirm").is("':checked'") == false)
            {
                alert("Lütfen sözleşmeyi onaylayınız");
                return;
            }

            //frmm
            if ($('input[name=captchaAvailable]').val() == '1')
            {
                $.fancybox.open({
                    href: '/Cart/CheckoutCustomCaptcha',
                    autoScale: true,
                    width: 230,
                    height: 230,
                    fitToView: true,
                    autoSize: false,
                    autoDimensions: true,
                    autoScale: false,
                    type: 'iframe',
                    afterClose: function ()
                    {
                        frmSubmitRefresh2();
                    }
                });
                return false;
            }

            if ($("#Use3D").is("':checked'") == true)
            {
                if (!confirm("Ödemenin gerçekleştirilmesi için bankanızın sayfalarına yönlendirileceksiniz. Daha önce Güvenli Alışveriş Platformu kaydınızı yapmadıysanız, bankanız önce bu kaydı yaptıracaktır. Bu aşamalarda çıkacak sorunlarda bankanızdan destek alınız.")) return false;
            }

            $('.paymentButton').css("visibility", "hidden");

            var action = $('#PaymentType').val();
            $('#SelectedAction').val(action);

            $('#frmRefresh').submit();
        }
        function frmSubmit(type)
        {
            $('.paymentButton').css("visibility", "hidden");
            if (type == 0)
            {
                $('#SelectedAction').val("");
            }
            $('#frmRefresh').submit();
        }
        function frmSubmitRefresh()
        {
            //frmm
            if ($('input[name=captchaAvailable]').val() == '1')
            {
                $.fancybox.open({
                    href: '/Cart/CheckoutCustomCaptcha',
                    autoScale: true,
                    width: 230,
                    height: 230,
                    fitToView: true,
                    autoSize: false,
                    autoDimensions: true,
                    autoScale: false,
                    type: 'iframe',
                    afterClose: function ()
                    {
                        frmSubmitRefresh2();
                    }
                });
                return false;
            }
            frmSubmit(0);
        }
        function frmSubmitRefresh2()
        {
            frmSubmit(0);
        }

    </script>
}
<script type="text/javascript">
    function contractview()
    {
        $("#dialog-contract").load("/Cart/CustomCheckOutAgreement");
    }
    $(function ()
    {
        var agrFancyWidth = 850;
        if ($(document).width() < agrFancyWidth)
        {
            agrFancyWidth = "100%;";
        }
        var agrFancyHeight = 650;
        if ($(document).height() < agrFancyHeight)
        {
            agrFancyHeight = "100%;";
        }

        $(".agreement").fancybox({
            width: agrFancyWidth,
            height: agrFancyHeight,
            fitToView: false,
            autoSize: false,
            autoDimensions: false,
            autoScale: false
        });
    });
    //Trigger
    (function ($)
    {
        $.each(['show', 'hide'], function (i, ev)
        {
            var el = $.fn[ev];
            $.fn[ev] = function ()
            {
                this.trigger(ev);
                return el.apply(this, arguments);
            };
        });
    })(jQuery);
</script>
